
const allServices = require('../db');
const { searchApi } = require('../api/search');
const { sleep } = require('../utils')

const insertSearch = async () => {
  const total = 1620;
  const pageSize = 20;
  for (let i = 0; i < total/pageSize; i++) {
    const keyWords = await allServices.queryClassify([pageSize*i, pageSize])
    keyWords.forEach(async element => {
      await allServices.addErrorLog(['正式请求', element.name])
      await searchApi(element.name)
    });
    const ran = Math.ceil(Math.random()*10)
    await sleep(ran * 1000)
  }
}

module.exports = insertSearch